﻿<%@ Import Namespace="System.Linq" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RouteXml.aspx.cs" Inherits="Route" %><?xml version="1.0"?>
<%
    int routeNum = int.Parse(Page.Request["route"]);
    BusLib.Route route = BusLib.Route.GetRouteByNumber(routeNum);

    int tripNum = 0;
    BusLib.Trip trip = null;
    if (Page.Request["trip"] != null)
    {
        tripNum = int.Parse(Page.Request["trip"]);

        trip = route.InServiceTrips.First(x => x.trip_id == tripNum);
    }
    else
    {
        trip = route.InServiceTrips.First();
    }
%>
<route num="<%= route.route_short_name %>">
    <trip id="<%= trip.trip_id %>">
        <headsign><%= trip.trip_headsign %></headsign>
        <length><%= trip.Length %></length>
        <start_time><%=trip.Stop_Times[0].departure_time.ToString() %></start_time>
        <end_time><%=trip.Stop_Times[trip.Stop_Times.Count - 1].departure_time.ToString() %></end_time>
        <duration><%=
            (trip.Stop_Times[trip.Stop_Times.Count - 1].departure_time 
               - trip.Stop_Times[0].departure_time).ToString() %></duration>
        
        <shape>
<%
    foreach (BusLib.Shape_Point point in trip.Shape.Shape_Points)
    {
%>            <point>
                <lat><%= point.shape_pt_lat %></lat>
                <lng><%= point.shape_pt_lon %></lng>
            </point>
<%}%>
        </shape>
        <stops>
<%
    foreach (BusLib.Stop_Time stopTime in trip.Stop_Times)
    {
%>          <stop id="<%= stopTime.Stop.stop_id %>">
                <stop_name><%= System.Web.HttpUtility.HtmlEncode(stopTime.Stop.stop_name) %></stop_name>
                <arrival_time><%= stopTime.arrival_time %></arrival_time>
                <departure_time><%= stopTime.departure_time %></departure_time>
                
                <lat><%= stopTime.Stop.stop_lat %></lat>
                <lon><%= stopTime.Stop.stop_lon %></lon>
            </stop>
    <%} %>
        </stops>
    </trip>
</route>
